package org.prototype.bank.web;

import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.prototype.bank.service.TransferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


@Controller
public class AccountsController{

    protected final Log logger = LogFactory.getLog(getClass());

	@Autowired
    private TransferService transferService;

	@RequestMapping("/accounts")
    public ModelAndView listAccounts() {
        ModelAndView mav = new ModelAndView();
        mav.setViewName("accounts");
        
        String now = (new Date()).toString();
        logger.info("Returning accounts view with " + now);
        
        mav.addObject("now", now);
        mav.addObject("accounts", this.transferService.getAccounts());
        return mav;
    }
}
